﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Wisery
{
    internal abstract class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        protected void RaisePropertyChanged(string name)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(name ?? string.Empty));
        }

        protected bool SetField<T>(ref T field, T value, params string[] names)
        {
            bool changed = !EqualityComparer<T>.Default.Equals(field, value);
            if (changed)
            {
                field = value;
                foreach (string name in names)
                {
                    this.RaisePropertyChanged(name);
                }
            }

            return changed;
        }
    }
}
